package redlib.backend.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import redlib.backend.annotation.Privilege;
import redlib.backend.dto.BillingDetailsDTO;
import redlib.backend.dto.query.BillingDetailsQueryDTO;
import redlib.backend.dto.query.NameQueryDTO;
import redlib.backend.dto.query.TimeQueryDTO;
import redlib.backend.model.Page;
import redlib.backend.model.Select;
import redlib.backend.service.BillingDetailsService;
import redlib.backend.vo.BillingDetailsVO;
import redlib.backend.vo.NameSelectVO;
import redlib.backend.vo.TimeSelectVO;

import java.util.List;

@RestController
@RequestMapping("/api/billingDetails")
public class BillingDetailsController {
    @Autowired
    private BillingDetailsService billingDetailsService;

    @PostMapping("addRecord")
    public void addRecord(@RequestBody BillingDetailsDTO billingDetailsDTO) {
        billingDetailsService.insert(billingDetailsDTO);
    }

    @PostMapping("listBillingDetails")
    @Privilege("page")
    public Page<BillingDetailsVO> listBillingDetails(@RequestBody BillingDetailsQueryDTO queryDTO) {
        return billingDetailsService.listByPage(queryDTO);
    }

    @PostMapping("updateBillingDetails")
    @Privilege("update")
    public Integer updateBillingDetails(@RequestBody BillingDetailsDTO billingDetailsDTO) {
        return billingDetailsService.updateBillingDetails(billingDetailsDTO);
    }
    @PostMapping("deleteBillingDetails")
    @Privilege("delete")
    public void deleteBillingDetails(@RequestBody List<Integer> ids) {
        billingDetailsService.deleteByCodes(ids);
    }


    @PostMapping("timeSelect")
    public Select<TimeSelectVO> timeSelect(@RequestBody TimeQueryDTO timeQueryDTO){
        return billingDetailsService.timeSelect(timeQueryDTO);
    }

    @PostMapping("nameSelect")
    public Select<NameSelectVO> nameSelect(@RequestBody NameQueryDTO nameQueryDTO){
        return billingDetailsService.nameSelect(nameQueryDTO);
    }

}
